package com.ghostbusters.fingertrack.gui;

import java.awt.Color;
import java.awt.Graphics;
import java.util.ArrayList;

import javax.swing.JPanel;

import com.ghostbusters.fingertrack.wii.IRPoint;
import com.ghostbusters.fingertrack.wii.WiiSubscriber;

public class DrawPanel extends JPanel {
	
	
	public final static int pointsTracked = 100;
	public final static float inverse = (float)1/(float)pointsTracked;
	
	int[] xpoints = new int[pointsTracked];
	int[] ypoints = new int[pointsTracked];
	int counter = 0;
	
	boolean refresh = true;
	
	public DrawPanel(){
		
	}
	
	
	public void newPoint(IRPoint coordinate) {
	
	xpoints[counter] = (int)(coordinate.getX()*MainFrame.XDIM*((double)45/(double)60));
	ypoints[counter] = (int)(coordinate.getY()*MainFrame.YDIM*((double)34/(double)60));
	counter++;
	if(counter>=pointsTracked) counter=0;
	
	//repaint();
	/*
	if (points.size() <= 100) {
		points.add(coordinate);
	}
	else {
		points.remove(0);
		points.add(coordinate);
	}
	*/
	}
	
	float initred = .85f;
	float initblue = .9f;
	float initgreen = .85f;
	
	float targetRed = .0f;
	float targetBlue = .7f;
	float targetGreen = .85f;
	
	float redStep = (targetRed-initred)/(pointsTracked+1);
	float blueStep = (targetBlue-initblue)/(pointsTracked+1);
	float greenStep = (targetGreen-initgreen)/(pointsTracked+1);
	
	public void paintComponent(Graphics g){

	float red = initred;
	float blue = initblue;
	float green = initgreen;
	try{
	for( int i = counter; i<xpoints.length; i++){
		g.setColor( new Color(red,green,blue));
		g.fillOval(xpoints[i], ypoints[i], 8, 8);
		red+=redStep;
		blue+=blueStep;
		green+=greenStep;
	}
	
	for( int i = 0; i<counter; i++){
		g.setColor( new Color(Math.abs(red),Math.abs(green),Math.abs(blue)));
		g.fillOval(xpoints[i], ypoints[i], 8, 8);
		red+=redStep;
		blue+=blueStep;
		green+=greenStep;
		}
	}
	catch(Exception e){
		e.printStackTrace();
		System.out.println("red value: "+red);
	}
	}
}

